<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h1>教师查看学生成绩</h1>
	<form id="showScore" method="post">
		<span> <label>科目：</label><select onchange="subjectChange()"
			id="subject" name="subject">
				<c:forEach items="${subjectList }" var="subList">
					<option value="${subList.sub_id }">${subList.name }</option>
				</c:forEach>
		</select>
		</span> <span> <label>学生姓名：</label><select
			id="student" name="studentName">
				<c:forEach items="${studentList }" var="stuList">
					<option value="${stuList.user_id }">${stuList.user_name }</option>
				</c:forEach>
		</select>
		</span>&nbsp; &nbsp; &nbsp; <span> <a title="查看分数" class="blue" id="chexkScoreBtn"> <i
				class="ace-icon fa fa-search-plus bigger-130"></i>
		</a>
		</span>&nbsp; &nbsp; <span> <i
			class="ace-icon glyphicon glyphicon-refresh" onclick="msg();"></i></span>
	</form>
	<h5>分数：</h5>
	<h2 id = "scoreH3" style="color: green"></h2>

	<script type="text/javascript">
		function subjectChange() {
			var sub_id = $("#subject").val();
			$.ajax({
				type : 'GET',
				url : '${contextPath }/teacher/scoreGetStudentBySubject',
				data : {
					sub_id : sub_id
				},
				dateType : "json",
				success : function(data) {
					var id = data.idList;
					var name = data.nameList;
					$("#student").empty();
					var htmlString = '';
					for (var i = 0; i < id.length; i++) {
						htmlString += '<option value="' + id[i] + '">'
								+ name[i] + '</option>';
					}
					$('#student').html(htmlString);
				},
				error : function(msg) {
					alert(msg);
				}
			});
		}
		function studentChange() {
			var userId = $("#student").val();
			$.ajax({
				type : 'GET',
				url : '${contextPath }/teacher/scoreGetSubjectByStudent',
				data : {
					userId : userId
				},
				dateType : "json",
				success : function(data) {
					var id = data.idList;
					var name = data.nameList;
					$("#subject").empty();
					var htmlString = '';
					for (var i = 0; i < id.length; i++) {
						htmlString += '<option value="' + id[i] + '">'
								+ name[i] + '</option>';
					}
					$('#subject').html(htmlString);
				},
				error : function(msg) {
					alert(msg);
				}
			});
		}
		function msg() {
			window.location.reload();
		}
		jQuery(function($) {
			$('#student').click(
					function() {
						var subId = $(
								'#showScore select[name="subject"]')
								.val();
						var stuId = $(
								'#showScore select[name="studentName"]')
								.val();
						$.ajax({
							type : 'POST',
							url : '${contextPath}/teacher/teacherChexkScore',
							data : {
								subId : subId,
								stuId : stuId
							},
							dataType : "json",
							success : function(data) {
								var htmlString = data.message;
								$('#scoreH3').html(htmlString);
								
							}
						});
			});
			
			$('#chexkScoreBtn').click(
					function(){
						var subId = $('#showScore select[name="subject"]')
							.val();
						var stuId = $('#showScore select[name="studentName"]')
							.val();
						$.ajax({
							type : 'POST',
							url : '${contextPath}/teacher/teacherChexkScore',
							data : {
								subId : subId,
								stuId : stuId
							},
							dataType : "json",
							success : function(data){
								var htmlString = data.message;
								$('#scoreH3').html(htmlString);
							}
						});
					})
		})
	</script>
</body>
</html>